package com.luckeys.controller;

import java.util.UUID;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import com.luckeys.contants.CommonContans;
import com.luckeys.service.LocationService;
import com.luckeys.vo.LocationVO;

@RestController
@RequestMapping(value = "/location", method = RequestMethod.POST)
public class LocationController {

	@Autowired
	private LocationService locationService;


	@RequestMapping(value = "/queryPage", consumes = "application/json", produces = "application/json")
	@ResponseBody
	public ModelMap queryLocationPage(@RequestBody LocationVO location) {
		ModelMap resultMap = new ModelMap();

		resultMap.put(CommonContans.STRUTS_DATA,
				locationService.queryLocationPage(location));
		resultMap.put(CommonContans.STRUTS_RESULT, CommonContans.STRUTS_SUCCESS);
		return resultMap;
	}
	
	@RequestMapping(value = "/queryList", consumes = "application/json", produces = "application/json")
	@ResponseBody
	public ModelMap queryLocationList(@RequestBody LocationVO location) {
		ModelMap resultMap = new ModelMap();
		resultMap.put(CommonContans.STRUTS_DATA,
				locationService.queryListLocation(location));
		resultMap.put(CommonContans.STRUTS_RESULT, CommonContans.STRUTS_SUCCESS);
		return resultMap;
	}

	@RequestMapping(value = "/addLocation", consumes = "application/json", produces = "application/json")
	@ResponseBody
	public ModelMap addLocation(@RequestBody LocationVO location) {
		ModelMap resultMap = new ModelMap();
		location.setLocationUuid(UUID.randomUUID().toString());
		resultMap.put(CommonContans.STRUTS_DATA, locationService.addLocation(location));
		resultMap
				.put(CommonContans.STRUTS_RESULT, CommonContans.STRUTS_SUCCESS);
		return resultMap;
	}

	@RequestMapping(value = "/deleteLocation", consumes = "application/json", produces = "application/json")
	@ResponseBody
	public ModelMap deleteLocation(String locationUuid) {
		ModelMap resultMap = new ModelMap();
		resultMap.put(CommonContans.STRUTS_DATA, locationService.deleteLocation(locationUuid));
		resultMap
				.put(CommonContans.STRUTS_RESULT, CommonContans.STRUTS_SUCCESS);
		return resultMap;
	}
	
	@RequestMapping(value = "/queryLocationById", consumes = "application/json", produces = "application/json")
	@ResponseBody
	public ModelMap queryLocationById(String locationUuid) {
		ModelMap resultMap = new ModelMap();
		LocationVO location = locationService.queryLocationById(locationUuid);
		resultMap.put(CommonContans.STRUTS_DATA, location);
		resultMap
				.put(CommonContans.STRUTS_RESULT, CommonContans.STRUTS_SUCCESS);
		return resultMap;
	}
	
	@RequestMapping(value = "/updateLocation", consumes = "application/json", produces = "application/json")
	@ResponseBody
	public ModelMap updateLocation(@RequestBody LocationVO location) {
		ModelMap resultMap = new ModelMap();
		resultMap.put(CommonContans.STRUTS_DATA, locationService.updateLocation(location));
		resultMap
				.put(CommonContans.STRUTS_RESULT, CommonContans.STRUTS_SUCCESS);
		return resultMap;
	}
}
